package se.webbzon.boltzmann.editor.component.sequence.panel;

import java.awt.GridLayout;
import java.util.Collection;

import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import se.webbzon.boltzmann.game.sequence.builder.dialogue.IntegerDialogueRow;

public class IntegerDialogueRowPanel extends AbstractDialogueRowPanel {
	
	// Auto generated serial version UID
	private static final long serialVersionUID = 4726975020597826166L;
	
	// The text fields of this row panel
	private final JTextField prefixInput, postfixInput, minInput, maxInput;
	
	/*============================================================
	Constructors
	============================================================*/

	public IntegerDialogueRowPanel(IntegerDialogueRow row) {
		super(row);
		
		JPanel valuePanel = new JPanel();
		valuePanel.setLayout(new GridLayout(4,2));
		
		valuePanel.add(new JLabel("Value prefix:"));
		prefixInput = new JTextField(row.getPrefix());
		valuePanel.add(prefixInput);
		
		valuePanel.add(new JLabel("Value postfix:"));
		postfixInput = new JTextField(row.getPostfix());
		valuePanel.add(postfixInput);
		
		valuePanel.add(new JLabel("Minimal value:"));
		minInput = new JTextField(row.getMinValue());
		valuePanel.add(minInput);
		
		valuePanel.add(new JLabel("Maximal value:"));
		maxInput = new JTextField(row.getMaxValue());
		valuePanel.add(maxInput);
		addPanel(valuePanel);
	}
	
	/*============================================================
	Public Methods
	============================================================*/
	
	@Override public boolean apply(Collection<String> errorMessages) {
		if (super.apply(errorMessages)) {
			IntegerDialogueRow row = (IntegerDialogueRow) getSequenceRow();
			row.setPrefix(prefixInput.getText());
			row.setPostfix(postfixInput.getText());
			row.setMinValue(minInput.getText());
			row.setMaxValue(maxInput.getText());
			return true;
		} else
			return false;
	}

}
